package com.xhkj.hk;


import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hikvision.artemis.sdk.kafka.data.push.VehicleExecute;
import com.hikvision.artemis.sdk.kafka.data.result.ExecuteResult;
import com.hikvision.artemis.sdk.kafka.entity.parse.result.VehicleAlarmData;
import com.hikvision.artemis.sdk.kafka.entity.parse.result.VehicleListData;
import com.hikvision.artemis.sdk.kafka.entity.parse.result.VehiclePassData;
import com.xhkj.dao.MyVehicleNoPassDataDao;
import com.xhkj.es.UploadVehicleData2ES;
import com.xhkj.model.MyVehicleNoPassData;

import lombok.extern.slf4j.Slf4j;

/**
 * 车辆数据业务处理实现
 */
@Slf4j
@Component
public class VehicleExecuteHandle extends VehicleExecute {
	@Autowired
	private MyVehicleNoPassDataDao dao;
	private static MyVehicleNoPassDataDao mydao;
	@PostConstruct
	public void init(){
		mydao=dao;
	}
    @Override
    public ExecuteResult execute(VehicleListData data) {
        try {
        	List<VehiclePassData> vehiclePassNoRecogList = data.getVehiclePassNoRecogList();
        	MyVehicleNoPassData md = new MyVehicleNoPassData();
        	if(vehiclePassNoRecogList.size()>0) {
        		UploadVehicleData2ES.insert(vehiclePassNoRecogList);
        		BeanUtils.copyProperties(vehiclePassNoRecogList.get(0), md);
        		md.setMyState(0);
        		md.setInsertTime(LocalDateTime.now());
        		mydao.save(md);
        	}
            return ExecuteResult.success();
        } catch (Exception e) {
        	log.error("车辆数据业务处理实现异常",e);
            return ExecuteResult.retry();
        }

    }
}
